// In this example I show you how you can build three pulses with Linear Polarization 
// in the y-direction
// Alexis A. Chacón Salazar April, 8th 2011

#include <iostream>
#include <complex>
#include<math.h>
#include <string>
#include "laser.h"

using namespace std;

int main()
{   	
	FILE *out0, *out1, *out2, *out3, *out4;
	FILE *out5, *out6, *out7, *out8, *out9; 
	
	out0=fopen("out0.txt","w");
	out1=fopen("out1.txt","w");
	
	out2=fopen("out2.txt","w");
/*	out3=fopen("out3.txt","w");
	
	out4=fopen("out4.txt","w");
	out5=fopen("out5.txt","w");

*/	
	/***=============================
	 ================================
	  Using the laser pulses librery 
	 ================================
	 ============================****/

	// PARAMETERS TO BUILD LASER PULSE
	
	int npulses= 3;	                       // Number of pulses	
	
	string env_name ="rsin2";              /**** 
												IMPORTANT The Name of the envelop, may be: 
											              konst, rect, sin2, gauss or rsin2.
											*****/ 
	
	double t01 = 0.0;						// Start time of the first pulse
	double dt     = 0.05;					// Temporary increase
	double blaser = 50.0;					// Time before the pulse atomic unit
	double alaser = 50.0;					// Time after the pulse atomic unit (a.u.)
	
	laser fpulse(npulses);					// Creator of Laser Pulses
		
	//First laser pulse 
	fpulse.I0[0]      = 1.0e13;				// Intensity W/cm^2 
	fpulse.e[0]       = 0.00;				// Elliptical of the pulse
	fpulse.w0[0]      = 1.0;				// Central frequency
   	fpulse.cycles0[0] = 4;					// Cycles number
   	fpulse.cep0[0]    = 0.0;				// Carrier Envelope Phase
	fpulse.phi_rel[0] = pi/2;               // Relative phase between the polarization Ex and Ey
	
	double periodIR = dospi/0.057;			// Period in a.u.

	fpulse.delay0[0]  = periodIR/2.0;		// Delay in a.u.	

	//Second laser pulse
	fpulse.I0[1]      = 1.0e13;				// Intensity W/cm^2 
	fpulse.e[1]       = 0.00;				// Elliptical of the pulse
	fpulse.w0[1]      = 1.0;				// Central frequency in a.u.
   	fpulse.cycles0[1] = 4;					// Cycles number
   	fpulse.cep0[1]    = -pi/2;				// Carrier Envelope Phase
	fpulse.phi_rel[1] = 0.0;				// Relative phase between the polarization Ex and Ey
	
	
	fpulse.delay0[1]  = periodIR/2.0;      // Delay (a.u.)
	
	//Second laser pulse
	fpulse.I0[2]      = 1.0e13;  		   // Intensity W/cm^2 
	fpulse.e[2]       = 0.00;  			   // Elliptical of the pulse
	fpulse.w0[2]      = 1.0;               // Central frequency in a.u.
   	fpulse.cycles0[2] = 4;                 // Cycles number
   	fpulse.cep0[2]    = pi/2;              // Carrier Envelope Phase
	fpulse.phi_rel[2] = 0;                 // Relative phase between the polarization Ex and Ey
	
	fpulse.envelope=env_name;               // Envelop name
	cout << "\n"<<fpulse.envelope<<endl;
	
   	fpulse.laser_pulses(dt, t01,  blaser,  alaser);  // Making the linear polarization pulse Ey
		
	// Save the laser pulse
	for (int ktime=0; ktime<fpulse.g.n; ktime++)
		fprintf(out0,"%e %e %e %e %e\n",
				fpulse.g.t[ktime],
				fpulse.efield.f[ktime][0], fpulse.avector.f[ktime][0],
				fpulse.efield.f[ktime][1], fpulse.avector.f[ktime][1]);
    //End save the laser pulse
	
	
    //**** Note:
	//****      fpulse.efield.f[ktime][0] is the Ex-ktime component of the electric field of the laser pulses
	//****      fpulse.efield.f[ktime][1] is the Ey-ktime component of the electric field of the laser pulses
	//****      fpulse.avector.f[ktime][0] is the Ax-ktime component of the vector potential of the laser pulses 
	//****      fpulse.avector.f[ktime][1] is the Ay-ktime component of the vector potential of the laser pulses 

	
	// Save each laser pulse
	for (int ktime=0; ktime<fpulse.g.n; ktime++)
		fprintf(out1,"%e %e %e %e %e %e %e %e %e\n",
				fpulse.g.t[ktime],
				fpulse.ef[0].f[ktime][0], fpulse.ef[0].f[ktime][1], 
				fpulse.av[0].f[ktime][0], fpulse.av[0].f[ktime][1],
				
				fpulse.ef[1].f[ktime][0], fpulse.ef[1].f[ktime][1], 
				fpulse.av[1].f[ktime][0], fpulse.av[1].f[ktime][1]);
    //End save each the laser pulse
	
	
    //**** Note:
	//****      fpulse.ef[0].f[ktime][0] is the Ex-ktime component of the electric field of the first laser pulse
	//****      fpulse.ef[0].f[ktime][1] is the Ey-ktime component of the electric field of the first laser pulse	
 	//****      fpulse.ef[1].f[ktime][1] is the Ex-ktime component of the electric field of the second laser pulse
 	//****      fpulse.ef[1].f[ktime][1] is the Ey-ktime component of the electric field of the second laser pulse	
	
	//****      fpulse.av[0].f[ktime][0] is the Ax-ktime component of the vector potential of the first laser pulse 
	//****      fpulse.av[0].f[ktime][1] is the Ay-ktime component of the vector potential of the first laser pulse 	
	//****      fpulse.av[1].f[ktime][0] is the Ax-ktime component of the vector potential of the second laser pulse 
	//****      fpulse.av[1].f[ktime][1] is the Ay-ktime component of the vector potential of the second laser pulse

	
	// Save envelope per pulse
	for (int ktime=0; ktime<fpulse.g.n; ktime++)
		fprintf(out2,"%e %e %e %e %e\n",
				fpulse.g.t[ktime],
				fpulse.env[0].f[ktime][0], fpulse.env[0].f[ktime][1], 

				fpulse.env[1].f[ktime][0], fpulse.env[1].f[ktime][1]);
    //End save envelope per pulse	
	
	/***===========================
	 ==============================***/

			
	fclose(out0);
	fclose(out1);   
	fclose(out2);
/*	fclose(out3);
	fclose(out4);
	fclose(out5);
*/	
	
}//End main

